"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_assets = require("../../../common/assets.js");
const _sfc_main = {
  data() {
    return {
      posts: []
    };
  },
  onLoad() {
    this.getPosts();
  },
  methods: {
    getPosts() {
      common_vendor.index.request({
        url: "http://localhost:3000/getPosts",
        success: (res) => {
          this.posts = res.data;
        }
      });
    },
    deletePost(id) {
      common_vendor.index.request({
        url: "http://localhost:3000/deletePost",
        method: "POST",
        data: { id },
        success: (res) => {
          this.getPosts();
        }
      });
    },
    editPost(post) {
      common_vendor.index.navigateTo({
        url: "EditPost/EditPost?post=" + encodeURIComponent(JSON.stringify(post))
      });
    },
    addPost() {
      common_vendor.index.navigateTo({
        url: "AddPost/AddPost"
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.f($data.posts, (post, index, i0) => {
      return {
        a: common_vendor.t(post.title),
        b: common_vendor.o(($event) => $options.deletePost(post.id), index),
        c: common_vendor.o(($event) => $options.editPost(post), index),
        d: index
      };
    }),
    b: common_assets._imports_0$1,
    c: common_assets._imports_1,
    d: common_assets._imports_2,
    e: common_vendor.o((...args) => $options.addPost && $options.addPost(...args))
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
